﻿using BlazorApp4.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.FileProviders;
using Hangfire;
using Hangfire.MemoryStorage;
using NETCore.MailKit.Core;
using BlazorApp4;
using Blazored.LocalStorage;
using Google.Api;
using BlazorApp4.Service;
using Microsoft.AspNetCore.Components.Server.Circuits;

var builder = WebApplication.CreateBuilder(args);



// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddDaprClient();
builder.Services.AddCors(x => x.AddPolicy("externalRequests",
                    policy => policy
                .WithOrigins("https://jsonip.com")));
builder.Services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
builder.Services.AddSingleton<CircuitHandler, TrackingCircuitHandler>();
/*builder.Services.AddHangfire(x => x
    .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
    .UseSimpleAssemblyNameTypeSerializer()
    .UseRecommendedSerializerSettings()
    .UseMemoryStorage());*/
//builder.Services.AddHangfireServer();
//builder.Services.AddTransient<IHostedService, HelloJobService>();
builder.Services.AddSignalR(options =>
{
    options.MaximumReceiveMessageSize = 102400000; // 设置最大消息大小为100MB
});
builder.Services.AddBlazoredLocalStorage();


//builder.Services.AddTransient<IEmailService, EmailService>();           //Scoped didn't seem to work. Singleton did work.
var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseStaticFiles(new StaticFileOptions {     
    ServeUnknownFileTypes = true,
    DefaultContentType = "application/x-msdownload" 
});
app.UseCors("externalRequests");

app.UseRouting();

app.MapBlazorHub();
//app.UseHangfireDashboard();
app.MapHub<BlazorChatHub>("/Chat");
app.MapFallbackToPage("/_Host");


/*BackgroundJob.Enqueue(() => Console.WriteLine(11111)); ;

BackgroundJob.Schedule(() => Console.WriteLine(22222),
    TimeSpan.FromMinutes(1));

RecurringJob.AddOrUpdate(
    "Run every 5 minutes", () => Console.WriteLine(333333),
    "5 * * * *");

RecurringJob.AddOrUpdate(
    "Run every day at 13:35", () => Console.WriteLine(444444),
     "35 13 * * *");*/
app.Run();
